***********Direct Effect***************

****For PRIs and universities
use "D:\Data and Code\PRI&U_Direct.dta", clear 

global xlist "size RD_Expenditure age lab"
xtset id year, delta(1)
xtdescribe 

g time = (year >= 2019) & !missing(year)
g treated = (shidian >0)&!missing(shidian)
g did = time*treated

* Regreesion_Original coefficients
xtreg sci did time treated $xlist i.year, fe
xtreg h_sci did time treated $xlist i.year, fe

* Regreesion_Standardized coefficients
norm did size RD_Expenditure age lab sci h_sci, method(zee) 

xtreg zee_sci did time treated zee_size zee_RD_Expenditure zee_age ///
 zee_lab i.year, fe
 xtreg zee_h_sci did time treated zee_size zee_RD_Expenditure zee_age ///
 zee_lab i.year, fe


***For PRIs

use "D:\Data and Code\PRI_Direct.dta", clear 

global xlist "size RD_Expenditure age lab"
xtset id year, delta(1)
xtdescribe 

g time = (year >= 2019) & !missing(year)
g treated = (shidian >0)&!missing(shidian)
g did = time*treated

* Hausman test
qui xtreg sci did time treated $xlist, fe 
est store FE 
qui xtreg sci did time treated $xlist, re 
est store RE
hausman FE RE, constant sigmamore

qui xtreg h_sci did time treated $xlist, fe 
est store FE 
qui xtreg h_sci did time treated $xlist, re 
est store RE
hausman FE RE, constant sigmamore


* Regreesion_Original coefficients
xtreg sci did time treated $xlist i.year, fe
xtreg h_sci did time treated $xlist i.year, fe

* Regreesion_Standardized coefficients
norm did size RD_Expenditure age lab sci h_sci, method(zee) 

xtreg zee_sci did time treated zee_size zee_RD_Expenditure zee_age ///
 zee_lab i.year, fe
 xtreg zee_h_sci did time treated zee_size zee_RD_Expenditure zee_age ///
 zee_lab i.year, fe

 
***For Universities

use "D:\Data and Code\U_Direct.dta", clear 

global xlist "size RD_Expenditure age lab"
xtset id year, delta(1)
xtdescribe 

g time = (year >= 2019) & !missing(year)
g treated = (shidian >0)&!missing(shidian)
g did = time*treated

* Hausman test
qui xtreg sci did time treated $xlist, fe 
est store FE 
qui xtreg sci did time treated $xlist, re 
est store RE
hausman FE RE, constant sigmamore

qui xtreg h_sci did time treated $xlist, fe 
est store FE 
qui xtreg h_sci did time treated $xlist, re 
est store RE
hausman FE RE, constant sigmamore


* Regreesion_Original coefficients
xtreg sci did time treated $xlist i.year, fe
xtreg h_sci did time treated $xlist i.year, fe

* Regreesion_Standardized coefficients
norm did size RD_Expenditure age lab sci h_sci, method(zee) 

xtreg zee_sci did time treated zee_size zee_RD_Expenditure zee_age ///
 zee_lab i.year, fe
 xtreg zee_h_sci did time treated zee_size zee_RD_Expenditure zee_age ///
 zee_lab i.year, fe
 

***********Mediating Effect***************
***For PRIs
use "D:\Data and Code\PRI_Mediate", clear  

global xlist "size RD_Expenditure lab age"
xtset id year, delta(1)
xtdescribe 

tab year, gen(d_year)
tab id, gen(d_id)

g time = (year >= 2019) & !missing(year)
g treated = (shidian >0)&!missing(shidian)
g did = time*treated

* Model_Original coefficients
gsem (sci <- did $xlist  i.year i.id) (sci <- hiring incentivizing) ///
(hiring <- did) (incentivizing <- did), nocapslatent

gsem (h_sci <- did $xlist  i.year i.id) (h_sci <- hiring incentivizing) ///
(hiring <- did) (incentivizing <- did), nocapslatent


* Model_Standardized coefficients
norm did size RD_Expenditure age lab ///
hiring incentivizing sci h_sci, method(zee) 

gsem (zee_sci <- did size zee_RD_Expenditure zee_age zee_lab i.year i.id) ///
  (zee_sci <- zee_hiring zee_incentivizing) ///
(zee_hiring <- did) (zee_incentivizing <- did), nocapslatent

gsem (zee_h_sci <- did size zee_RD_Expenditure zee_age zee_lab i.year i.id) ///
  (zee_h_sci <- zee_hiring zee_incentivizing) ///
(zee_hiring <- did) (zee_incentivizing <- did), nocapslatent


***For Universities
use "D:\Data and Code\U_Mediate", clear  

global xlist "size RD_Expenditure lab age"
xtset id year, delta(1)
xtdescribe 

tab year, gen(d_year)
tab id, gen(d_id)

g time = (year >= 2019) & !missing(year)
g treated = (shidian >0)&!missing(shidian)
g did = time*treated

* Model_Original coefficients
gsem (sci <- did $xlist  i.year i.id) (sci <- hiring incentivizing) ///
(hiring <- did) (incentivizing <- did), nocapslatent

gsem (h_sci <- did $xlist  i.year i.id) (h_sci <- hiring incentivizing) ///
(hiring <- did) (incentivizing <- did), nocapslatent


* Model_Standardized coefficients
norm did size RD_Expenditure age lab ///
hiring incentivizing sci h_sci, method(zee) 

gsem (zee_sci <- did size zee_RD_Expenditure zee_age zee_lab i.year i.id) ///
  (zee_sci <- zee_hiring zee_incentivizing) ///
(zee_hiring <- did) (zee_incentivizing <- did), nocapslatent

gsem (zee_h_sci <- did size zee_RD_Expenditure zee_age zee_lab i.year i.id) ///
  (zee_h_sci <- zee_hiring zee_incentivizing) ///
(zee_hiring <- did) (zee_incentivizing <- did), nocapslatent











                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              



